package com.easy;

/**
 * Created by Lxk on 2020/1/4.
 */
public class Solution788 {

    private static final char[] validNum = {'0', '1', '2', 'x', 'x', '5', '6', 'x', '8', '9'};

    private static final char[] changeValidNum = {'x', 'x', '2', 'x', 'x', '5', '6', 'x', 'x', '9'};

    private boolean isReverse(int num) {
        String numStr = String.valueOf(num);
        //1.确认是否有效
        for (int i = 0; i < numStr.length(); i++) {
            if (numStr.charAt(i) != validNum[numStr.charAt(i) - '0']) {
                return false;
            }
        }
        //2.确认数值是否变化
        boolean flag = false;
        for (int i = 0; i < numStr.length(); i++) {
            if (numStr.charAt(i) == changeValidNum[numStr.charAt(i) - '0']) {
                flag = true;
            }
        }
        return flag;
    }

    public int rotatedDigits(int N) {
        int count = 0;
        for (int i = 1; i <= N; i++) {
            if (isReverse(i)) {
                count++;
            }
        }
        return count;
    }

    public static void main(String[] args) {
        Solution788 solution788 = new Solution788();
        System.out.println(solution788.rotatedDigits(10));
    }

}
